/**
 * Created on May 13, 2007
 */
package jvs.vfs.tools;

import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;

/**
 * @author qiangli
 * 
 */
public class BasicDialog extends JDialog {

	private static final long serialVersionUID = 1L;

	public static final int APPROVE_OPTION = 1;

	public static final int CANCEL_OPTION = 2;

	protected int option = CANCEL_OPTION;

	protected static Dimension HGAP10 = new Dimension(10, 1);

	protected static Dimension VGAP10 = new Dimension(1, 10);

	protected JButton okay;

	protected JButton cancel;

	public BasicDialog(Frame owner, boolean modal) {
		super(owner, modal);
	}

	public BasicDialog(Dialog owner, boolean modal) {
		super(owner, modal);
	}

	public int showDialog() {
		//show();
		setVisible(true);
		return option;
	}

	protected void addLabelTextRows(JComponent[] labels,
			JComponent[] textFields, GridBagLayout gridbag, Container container) {
		GridBagConstraints c = new GridBagConstraints();
		c.anchor = GridBagConstraints.EAST;
		int numLabels = labels.length;

		for (int i = 0; i < numLabels; i++) {
			
			c.gridwidth = GridBagConstraints.RELATIVE;
			c.fill = GridBagConstraints.NONE;
			c.weightx = 0.0;
			gridbag.setConstraints(labels[i], c);
			container.add(labels[i]);

			c.gridwidth = GridBagConstraints.REMAINDER;
			c.fill = GridBagConstraints.HORIZONTAL;
			c.weightx = 1.0;
			gridbag.setConstraints(textFields[i], c);
			container.add(textFields[i]);
			
			labels[i].setFont(new Font("Times New Roman", Font.BOLD, 12));
			textFields[i].setFont(new Font("Times New Roman", Font.PLAIN, 14));
		}
	}

	protected void center() {
		//setLocationRelativeTo(null);
		setLocationRelativeTo(getOwner());

		//Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		//setLocation((d.width - getSize().width) / 2,
		//		(d.height - getSize().height) / 2);
	}
}
